﻿using RimWorld;
using Verse;
using Verse.Sound;

namespace ARMIR {
    /// <summary>
    /// 能力-心绪力场，通过使用能力给予使用者装备来达到获得护盾的能力
    /// </summary>
    public class CompAbilityEffect_MindShield : CompAbilityEffect {
        private Pawn Pawn => parent.pawn;

        public new CompProperties_MindShield Props => (CompProperties_MindShield)props;

        public override bool AICanTargetNow(LocalTargetInfo target) {
            if (Pawn.Faction == Faction.OfPlayer) {
                return false;
            }

            return true;
        }

        public override void Apply(LocalTargetInfo target, LocalTargetInfo dest) {
            if (target.Pawn != null && Props.thingdef != null) {
                Apparel newApparel = ThingMaker.MakeThing(Props.thingdef) as Apparel;
                target.Pawn.apparel.Wear(newApparel, dropReplacedApparel: false, locked: true);
                SoundDef.Named("ARMIR_magicHitStart").PlayOneShot(new TargetInfo(Pawn.Position, Pawn.Map)); //启动音效
            }
            if (target.Pawn != null && Props.hediff != null)
            {
                Hediff mindShield = HediffMaker.MakeHediff(Props.hediff, Pawn);
                Pawn.health.AddHediff(mindShield);
            }
        }
    }
}